/**
 * 
 */
package com.yidu.menuProject.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.yidu.menuProject.action.vo.EhyRoleVo;
import com.yidu.menuProject.commont.Tools;
import com.yidu.menuProject.dao.EhyManagerRoleModelMapper;
import com.yidu.menuProject.dao.EhyRoleModelMapper;
import com.yidu.menuProject.dao.EhyRoleModuleModelMapper;
import com.yidu.menuProject.model.EhyRoleModel;
import com.yidu.menuProject.model.EhyRoleModuleModel;



/**
 * 
 *@author xc
 *@version 1.0
 */
@Service
public class EhyRoleServiceImpl implements EhyRoleService{

	@Resource 
	public EhyRoleModelMapper ehyRoleDao;
	@Resource
	public EhyManagerRoleModelMapper ehyManagerRoleDao;
	@Resource
	public EhyRoleModuleModelMapper ehyRoleModuleDao;
	
	@Override
	public int insertSelective(EhyRoleVo vo) {
		
		ehyRoleDao.insertSelective(vo);
		String[] module=vo.getCheckName().split("_");
		for (String string : module) {
			EhyRoleModuleModel mr=new EhyRoleModuleModel();
			mr.setRmId(Tools.getRandomString(20));
			mr.setModId(string);
			mr.setRoleId(vo.getRoleId());
			ehyRoleModuleDao.insertSelective(mr);
		}
		
		return 1;
	}

	@Override
	public int updateByPrimaryKeySelective(EhyRoleVo vo) {
		
		 ehyRoleDao.updateByPrimaryKeySelective(vo);
		 String[] module=vo.getCheckName().split("_");
			for (String string : module) {
				EhyRoleModuleModel mr=new EhyRoleModuleModel();
				ehyRoleModuleDao.deleteRole(mr.getRoleId());
				mr.setRmId(Tools.getRandomString(20));
				mr.setModId(string);
				mr.setRoleId(vo.getRoleId());
				ehyRoleModuleDao.insertSelective(mr);
			}
			return 1;
	}

	@Override
	public int delete(String roleId) {
		
		return ehyRoleDao.deleteByPrimaryKey(roleId);
	}

	@Override
	public List<EhyRoleVo> findByMan(EhyRoleVo vo) {
		
		return null;
	}

	@Override
	public EhyRoleVo findById(String id) {
		EhyRoleModel po = new EhyRoleModel();
		EhyRoleVo vo = new EhyRoleVo();
		po=ehyRoleDao.findById(id);
		BeanUtils.copyProperties(po, vo);
		return vo;
	}

	@Override
	public int deleteByPrimaryKey(String manId) {
		
		return ehyRoleDao.deleteByPrimaryKey(manId);
	}

	@Override
	public List<EhyRoleModel> selectAll(EhyRoleVo vo) {
		
		return ehyRoleDao.selectAll(vo);
	}

	@Override
	public int selectCount(EhyRoleVo vo) {
		
		return ehyRoleDao.selectCount(vo);
	}

	@Override
	public List<EhyRoleModel> selectManagerRole(String manId) {
		
		return ehyManagerRoleDao.selectManagerRole(manId);
	}

	@Override
	public List<EhyRoleModel> selectRole(EhyRoleVo vo) {
		// TODO Auto-generated method stub
		return ehyRoleDao.selectRole(vo);
	}


	
}